package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfig{

    public static final String DIRECT_EXCHANGE = "direct.exchange";
    public static final String DIRECT_ROUTE_KEY = "direct.key";
    public static final String DIRECT_QUEUE = "direct.queue";


    /**
     * 交换机持久化的三种代码编写方式
     */
    @Bean
    public DirectExchange directExchange(){
        //return new DirectExchange(DIRECT_EXCHANGE); //默认写法
        //return new DirectExchange(DIRECT_EXCHANGE, true, false);
        return ExchangeBuilder.directExchange(DIRECT_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue directQueue(){
        //return new Queue(DIRECT_QUEUE); //默认写法
        //return new Queue(DIRECT_QUEUE,true);
        return QueueBuilder.durable(DIRECT_QUEUE).build();
    }

    @Bean
    public Binding bindDirectQueue(){
        return BindingBuilder.bind(directQueue()).to(directExchange()).with(DIRECT_ROUTE_KEY);
    }


}
